package com.example.game;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;

public class SelectLevel extends Activity implements OnClickListener {
	GameView view ;
	ImageButton six, nine;
	Board board = new Board();
	int playId;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_select_level);

		six = (ImageButton) findViewById(R.id.six);
		nine = (ImageButton) findViewById(R.id.nine);
		
		six.setOnClickListener(this);
		nine.setOnClickListener(this);
	}

	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.select_level, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.six:
			playId=1;
			break;
		case R.id.nine:
			playId=2;
			break;
		}
		view = new GameView(this,playId);
		setContentView(view);
	}
	@Override
	public void onBackPressed() {
		viewdialog();
	}
	public void viewdialog(){
		// custom dialog
		final Dialog dialog = new Dialog(view.getContext());
		dialog.setContentView(R.layout.alertdialog);
		dialog.setTitle("pause");
		Button resume = (Button) dialog.findViewById(R.id.button1);
		Button mainmenu = (Button) dialog.findViewById(R.id.button2);
		Button exit = (Button) dialog.findViewById(R.id.button3);
		// if button is clicked, close the custom dialog
		resume.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dialog.dismiss();
			}
		});
		mainmenu.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
	             Intent main = new Intent(SelectLevel.this, main.class);
	             startActivity(main);
			}
		});
		exit.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
	        	 android.os.Process.killProcess(android.os.Process.myPid());
			}
		});
		dialog.show();
	}
}
